package pkg;

//Beverage Item
//Contains sub-menu

import java.util.ArrayList;
import java.util.Scanner;

public class Beverage extends Product{

	public static final double SMALL_VOLUME = 2.5;
	public static final double MEDIUM_VOLUME = 3.5;
	public static final double LARGE_VOLUME = 5.0;

	public static final double SMALL_MODIFIER = 1.0;
	public static final double MEDIUM_MODIFIER = 1.15;
	public static final double LARGE_MODIFIER = 1.25;

	String bev_label;
	ArrayList<Toppings> bev_toppings;
	ArrayList<Size> bev_sizes;
	Flavor bev_flavor;
	Beverage_Type bev_type;
	Size bev_size;

	public Beverage()
	{
		bev_label = "SubMenu prompt stub object";
		bev_sizes = new ArrayList<Size>();
		bev_sizes.add(new Size_Small(SMALL_VOLUME, SMALL_MODIFIER));
		bev_sizes.add(new Size_Medium(MEDIUM_VOLUME, MEDIUM_MODIFIER));
		bev_sizes.add(new Size_Large(LARGE_VOLUME, LARGE_MODIFIER));
		bev_toppings = new ArrayList<Toppings>();
	}
	public Beverage(Beverage_Type c_bevtype, Flavor c_flavor, Size c_size){
		bev_type = c_bevtype;
		bev_flavor = c_flavor;
		bev_size = c_size;
		bev_sizes = new ArrayList<Size>();
		bev_sizes.add(new Size_Small(SMALL_VOLUME, SMALL_MODIFIER));
		bev_sizes.add(new Size_Medium(MEDIUM_VOLUME, MEDIUM_MODIFIER));
		bev_sizes.add(new Size_Large(LARGE_VOLUME, LARGE_MODIFIER));

		bev_toppings = new ArrayList<Toppings>();
	}
	public String getGenericLabel()
	{
		return "Beverage";
	}
	public String getName(){
		String ret_String = new String();		
		return ret_String;
	}

	public double getPrice(){
		double base = bev_type.getBasePrice();
		base *= bev_size.getPriceModifier();
		double retPrice = base;

		if(!bev_toppings.isEmpty())
		{
			for(Toppings t : bev_toppings)
			{
				retPrice += t.getPrice();
			}
		}
		return retPrice;
	}
	
	public void addTopping(Toppings top)
	{
		bev_toppings.add(top);
	}

	public String getDirections(){
		String retString = new String();
		retString += "Get cup\n";
		retString += bev_type.getDirections();
		retString += "Add straw\n";
		return retString;
	}

	public Beverage submenuPrompt()
	{	
		Scanner in = new Scanner(System.in);
		int selection;
		ArrayList<Beverage_Type> bevlist = Beverage_Type.getTypes();
		ArrayList<Flavor> flavorList;
		ArrayList<Toppings> toppingsList;

		Beverage_Type selected_bevtype;
		Flavor selected_flavor;
		Size selected_size;
		Beverage retBeverage;

		//Select the beverage type
		System.out.println("Please select the type of beverage the customer ordered:");

		for(int i = 1; i < bevlist.size()+1; i++)
		{
			System.out.println("\t"+i+" - " + bevlist.get(i - 1).getLabel());
		}
		System.out.print("\nMake a selection:");
		selection = in.nextInt();

		while (selection > bevlist.size() || selection < 1)
		{
			System.out.println("\nInvalid selection, please select again.");
			selection = in.nextInt();
		}
		selected_bevtype = bevlist.get(selection - 1);
		flavorList = selected_bevtype.getFlavors();
		selection = -1;
		//Select the beverage flavor
		System.out.println("Please select the flavor of " + 
				selected_bevtype.getLabel() +
		" the customer ordered:");

		for(int i = 1; i < flavorList.size()+1; i++)
		{
			System.out.println("\t"+i+" - " + flavorList.get(i - 1).getLabel());
		}
		System.out.print("\nMake a selection:");
		selection = in.nextInt();

		while (selection > flavorList.size() || selection < 1)
		{
			System.out.println("\nInvalid selection, please select again.");
			selection = in.nextInt();
		}

		selected_flavor = flavorList.get(selection - 1);
		selection = -1;

		//Select the beverage size
		System.out.println("Please select the size of " + 
				selected_bevtype.getLabel() +
		" the customer ordered:");

		for(int i = 1; i < bev_sizes.size()+1; i++)
		{
			System.out.println("\t"+i+" - " + bev_sizes.get(i - 1).getLabel());
		}
		System.out.print("\nMake a selection:");
		selection = in.nextInt();

		while (selection > bev_sizes.size() || selection < 1)
		{
			System.out.println("\nInvalid selection, please select again.");
			selection = in.nextInt();
		}

		selected_size = bev_sizes.get(selection - 1);
		retBeverage = new Beverage(selected_bevtype, selected_flavor, selected_size);

		//Select the toppings
		toppingsList = Toppings.getTypes();
		System.out.println("Please select the topping the customer ordered.");

		System.out.println("\t0 - No toppings");
		for(int i = 1; i < toppingsList.size()+1; i++)
		{
			System.out.println("\t"+i+" - " + toppingsList.get(i - 1).getLabel());
		}
		System.out.print("\nMake a selection:");
		selection = in.nextInt();

		while (selection > toppingsList.size() || selection < 0)
		{
			System.out.println("\nInvalid selection, please select again.");
			selection = in.nextInt();
		}

		if(selection != 0)
		{
			retBeverage.addTopping(toppingsList.get(selection -1));
		}
		return retBeverage;
	}

	public static void main(String[] args)
	{
		Beverage stub = new Beverage();
		Beverage myBev = stub.submenuPrompt();
	}
}
